﻿#region

using System.Collections.Generic;
using System.Web.Routing;
using CuongHanh.Models;

#endregion

namespace CuongHanh.Context
{
    public class UrlManager
    {
        #region Wood
        public static string LinkWoodCategory(int id,
               string name)
        {
            RouteValueDictionary routeValueDictionary = new RouteValueDictionary()
                                                        {
                                                                {"id", id},
                                                                {"name", name}
                                                        };

            VirtualPathData routeCollection = RouteTable.Routes.GetVirtualPath(null,
                    "wood-category",
                    routeValueDictionary);
            return routeCollection != null
                    ? routeCollection.VirtualPath
                    : "javascript:void(0);";
        }

        public static string LinkWoodSubCategory(int id,
                string name,
                string categoryName)
        {
            RouteValueDictionary routeValueDictionary = new RouteValueDictionary()
                                                        {
                                                                {"id", id},
                                                                {"name", name},
                                                                {"categoryName", categoryName}
                                                        };

            VirtualPathData routeCollection = RouteTable.Routes.GetVirtualPath(null,
                    "wood-sub-category",
                    routeValueDictionary);
            return routeCollection != null
                    ? routeCollection.VirtualPath
                    : "javascript:void(0);";
        }
        public static string LinkWoodProductDetail(int id,
                string name)
        {
            RouteValueDictionary routeValueDictionary = new RouteValueDictionary()
                                                        {
                                                                {"id", id},
                                                                {"name", name}
                                                        };

            VirtualPathData routeCollection = RouteTable.Routes.GetVirtualPath(null,
                    "wood-product-detail",
                    routeValueDictionary);
            return routeCollection != null
                    ? routeCollection.VirtualPath
                    : "javascript:void(0);";
        }
        #endregion

        #region Stone
        public static string LinkStoneCategory(int id,
               string name)
        {
            RouteValueDictionary routeValueDictionary = new RouteValueDictionary()
                                                        {
                                                                {"id", id},
                                                                {"name", name}
                                                        };

            VirtualPathData routeCollection = RouteTable.Routes.GetVirtualPath(null,
                    "stone-category",
                    routeValueDictionary);
            return routeCollection != null
                    ? routeCollection.VirtualPath
                    : "javascript:void(0);";
        }

        public static string LinkStoneSubCategory(int id,
                string name,
                string categoryName)
        {
            RouteValueDictionary routeValueDictionary = new RouteValueDictionary()
                                                        {
                                                                {"id", id},
                                                                {"name", name},
                                                                {"categoryName", categoryName}
                                                        };

            VirtualPathData routeCollection = RouteTable.Routes.GetVirtualPath(null,
                    "stone-sub-category",
                    routeValueDictionary);
            return routeCollection != null
                    ? routeCollection.VirtualPath
                    : "javascript:void(0);";
        }
        public static string LinkStoneProductDetail(int id,
                string name)
        {
            RouteValueDictionary routeValueDictionary = new RouteValueDictionary()
                                                        {
                                                                {"id", id},
                                                                {"name", name}
                                                        };

            VirtualPathData routeCollection = RouteTable.Routes.GetVirtualPath(null,
                    "stone-product-detail",
                    routeValueDictionary);
            return routeCollection != null
                    ? routeCollection.VirtualPath
                    : "javascript:void(0);";
        }
        #endregion
       

        

        public static string LinkDesignAndCustomise(int id,
                string name)
        {
            RouteValueDictionary routeValueDictionary = new RouteValueDictionary()
                                                        {
                                                                {"id", id},
                                                                {"designName", name.ToUrlName()},
                                                        };

            VirtualPathData routeCollection = RouteTable.Routes.GetVirtualPath(null,
                    "gem-design-customise",
                    routeValueDictionary);
            return routeCollection != null
                    ? routeCollection.VirtualPath
                    : "javascript:void(0);";
        }

        public static string LinkStaticPage(StaticPages staticPage,string language)
        {
            StaticPage item = CacheContext<StaticPage>.Singleton.GetObject((int)staticPage);
            if (item == null) return "javascript:void(0);";
            RouteValueDictionary routeValueDictionary = new RouteValueDictionary()
                                                        {
                                                                { "name", language==AppUtil.LANGUAGE_EN?item.NameEn:item.NameVi},
                                                                { "id",item.Id},
                                                        };

            VirtualPathData routeCollection = RouteTable.Routes.GetVirtualPath(null,
                    "gem-static-page",
                    routeValueDictionary);
            return routeCollection != null
                    ? routeCollection.VirtualPath
                    : "javascript:void(0);";
        }

        public static string LinkStaticPage1(int id)
        {
            RouteValueDictionary routeValueDictionary = new RouteValueDictionary()
                                                        {
                                                                {"id", id}
                                                        };

            VirtualPathData routeCollection = RouteTable.Routes.GetVirtualPath(null,
                    "page-khuyen-mai",
                    routeValueDictionary);
            return routeCollection != null
                    ? routeCollection.VirtualPath
                    : "javascript:void(0);";
        }

        #region static page
        public static string LinkStaticPages(StaticPages staticPage, string language)
        {
            return string.Empty;
            StaticPage item= CacheContext<StaticPage>.Singleton.GetObject((int) staticPage);
            RouteValueDictionary routeValueDictionary = new RouteValueDictionary()
                                                        {
                                                                { "namePage", language==AppUtil.LANGUAGE_EN?item.NameEn:item.NameVi}
                                                        };

            VirtualPathData routeCollection = RouteTable.Routes.GetVirtualPath(null,
                string.Format("page-{0}-{1}", language==AppUtil.LANGUAGE_EN?item.NameEn:item.NameVi, item.Id),
                    routeValueDictionary);
            return routeCollection != null
                    ? routeCollection.VirtualPath
                    : "javascript:void(0);";
        }

        #endregion

        public static string GetLinkByUrl(string url)
        {
            return string.Format("{0}/{1}",
                    AppUtil.CurrentDomain,url);
        }
    }

    public class ActionRouteValue
    {
        private Dictionary<string,RouteValue> routeValues =new Dictionary<string, RouteValue>();

        public void InIt()
        {
            routeValues["wood-index"]=new RouteValue()
                                      {
                                              Key = "wood-index",
                                              UrlEn = "go-trang-tri-cong-trinh",
                                              UrlVi = "go-trang-tri-cong-trinh",
                                              Controller = "wood",
                                              Action = "index"
                                      };
            routeValues["gem-index"] = new RouteValue()
            {
                Key = "gem-index",
                UrlEn = "trang-suc",
                UrlVi = "trang-suc",
                Controller = "gem",
                Action = "index"
            };
        }


        public RouteValue GetRouteValue(string key)
        {
            return routeValues.ContainsKey(key)
                    ? routeValues[key]
                    : null;
        }

    }

}
